#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;

int t, l1, r1, l2, r2;
int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> t;
    while (t--) {
        cin >> l1 >> r1 >> l2 >> r2;

        if (l1 > l2) {
            swap(l1, l2);
            swap(r1, r2);
        }

        int ans;
        if (l2 <= r1) ans = max(l1, l2);
        else ans = min(l1, r1) + min(l2, r2);
        cout << ans << endl;
    }
    return 0;
}